package bishi.day18_5_14;

import java.util.Scanner;

//字符串通配符
public class wildcard {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            String str1 = sc.nextLine().toLowerCase();
            String str2 = sc.nextLine().toLowerCase();
            System.out.println(isTrue(str1,str2));
        }
    }

    public static boolean isTrue(String str1, String str2) {
        int t = str1.length();
        int s = str2.length();
        boolean[][] dp = new boolean[s+1][t+1];
        dp[0][0] = true;
        for (int i = 0; i < s + 1; i++) {
            for (int j = 1; j < t + 1; j++) {
                if (str1.charAt(j - 1) == '*') {
                    if (i == 0) {
                        dp[i][j] = dp[i][j - 1];
                    }else {
                        if (isPass(str2.charAt(i - 1))) {
                            dp[i][j] = dp[i - 1][j] || dp[i][j - 1];
                        }
                    }
                }else if (i > 0 && isPass(str2.charAt(i - 1)) && (str1.charAt(j - 1) == '?' || str1.charAt(j - 1) == str2.charAt(i - 1))){
                    dp[i][j] = dp[i - 1][j - 1];
                }
            }
        }
        return dp[s][t];
    }

    private static boolean isPass(char c) {
        return c == '.' || (c >= 'a' && c <= 'z') || (c >= '0' && c <= '9');
    }
}